home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Framework / Includes / UFile.h < prev    next >
Encoding:
Text File  |  1996-04-03  |  12.4 KB  |  388 lines  |  [TEXT/MPS ]

  1. // UFile.h
  2. // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
  3.  
  4. #ifndef __UFILE__
  5. #define __UFILE__
  6.  
  7. // MacApp
  8.  
  9. #ifndef __UOBJECT__
  10. #include "UObject.h"
  11. #endif
  12.  
  13. #ifndef __USCRIPTABLEOBJECT__
  14. #include "UScriptableObject.h"
  15. #endif
  16.  
  17. // Toolbox
  18.  
  19. #ifndef __ALIASES__
  20. #include <Aliases.h>
  21. #endif
  22.  
  23. #ifndef __STANDARDFILE__
  24. #include <StandardFile.h>
  25. #endif
  26.  
  27. //----------------------------------------------------------------------------------------
  28. // TFile
  29. //----------------------------------------------------------------------------------------
  30.  
  31. const OSType kFolderType = 'fold';
  32. const OSType kFolderCreator = '\?\?\?\?';
  33.  
  34. const OSType kGenericType = 'TEXT';
  35. const OSType kGenericCreator = '\?\?\?\?';
  36.  
  37. enum ResourceUsage
  38. {
  39.     needResourceFork,
  40.     preferResourceFork,
  41.     noResourceFork
  42. };
  43.  
  44. const Boolean kUsesDataFork = TRUE;
  45. const ResourceUsage kUsesRsrcFork = preferResourceFork;    
  46. const Boolean kDataOpen = TRUE;    
  47. const Boolean kRsrcOpen = TRUE;    
  48.  
  49.  
  50. class TFile : public TObject, public MScriptableObject
  51. {
  52.     MA_DECLARE_CLASS;
  53.     
  54. public:
  55.  
  56.     TFile();
  57.         // Constructor
  58.         
  59.     void IFile(OSType itsFileType,
  60.                               OSType itsCreator,
  61.                               Boolean usesDataFork,
  62.                               ResourceUsage usesRsrcFork,
  63.                               Boolean keepsDataOpen,
  64.                               Boolean keepsRsrcOpen);
  65.         // Initialization method for TFile
  66.  
  67.     virtual ~TFile();
  68.  
  69.     //------------------------------------------------------------------------------------
  70.     // File Specification
  71.     //------------------------------------------------------------------------------------
  72.  
  73.     virtual void Specify(const FSSpec& theFile);
  74.         // Specify the file by its FSSpec.If the file has already opened a file, Specify
  75.         // will attempt to close the file before re-identifying the file
  76.  
  77.     virtual void SpecifyWithStandardFileReply(const StandardFileReply& itsReply);
  78.         // Specify a file with the information returned from CustomGetFile/CustomPutFile
  79.         // This will also set the filetype and scripttag, and indicates if the
  80.         // file is a stationery pad.
  81.         
  82.     virtual OSErr SpecifyWithSFReply(const SFReply& itsReply);
  83.         // Specify a file with the information returned from SFPGetFile/SFPPutFile
  84.         // This will also set the filetype.
  85.         
  86.     virtual OSErr SpecifyWithAlias(AliasHandle alias);
  87.         // Similar to TFile::Specify except the file is specified with an alias.  Also queries
  88.         // the finder information to determine the real filetype, creator, and
  89.         // whether or not the file pointed to by the alias is a stationery pad.
  90.  
  91.     virtual void SpecifyWithFile(TFile* aFile);
  92.         // Make this file reference the same file as aFile.
  93.  
  94.     virtual OSErr SpecifyWithTrio(short volRefNum, long dirID, const CStr63& name);
  95.         // Specify a file by volrefnum, dir ID, and filename. If dirID is zero, it then
  96.         // volRefNum is assumed to be a working directory and will be resolved to a
  97.         // directory ID
  98.  
  99.     //------------------------------------------------------------------------------------
  100.     // Creating/Opening/Closing/Deleting
  101.     //------------------------------------------------------------------------------------
  102.  
  103.     virtual OSErr CloseFile();
  104.         // Close the forks of the file irrespective of the fKeepOpen fields
  105.  
  106.     virtual OSErr CloseFileIfNotKeptOpen();
  107.         // Close the file respecting whether or not the data and resource fork should
  108.         // be left open.
  109.         
  110.     virtual OSErr CloseDataFork();
  111.         // Close the data fork. Called by CloseFile
  112.  
  113.     virtual OSErr CloseRsrcFork();
  114.         // Close the rsrc fork. Called by CloseFile
  115.  
  116.     virtual OSErr CreateFile();
  117.         // Create the file
  118.  
  119.     virtual OSErr CreateDataFork();
  120.         // Create the data fork of the file. Called by CreateFile
  121.  
  122.     virtual OSErr CreateRsrcFork();
  123.         // Create the rsrc fork of the file. Called by CreateFile
  124.  
  125.     virtual OSErr DeleteFile();
  126.         // Close the file and delete it.
  127.  
  128.     virtual OSErr OpenFile();
  129.         // Open the forks of the file irrespective of the fKeepOpen fields
  130.  
  131.     virtual OSErr OpenFileIfKeptOpen();
  132.         // Open the file with the fDataPermission and fRsrcPermission respecting the
  133.         // fKeepOpen fields
  134.  
  135.     virtual OSErr OpenDataFork(SignedByte permission);
  136.         // Open the data fork of the file. Called by OpenFile
  137.  
  138.     virtual OSErr OpenRsrcFork(SignedByte permission);
  139.         // Open the rsrc fork of the file. Called by OpenFile
  140.  
  141.  
  142.     //------------------------------------------------------------------------------------
  143.     // file attributes
  144.     //------------------------------------------------------------------------------------
  145.  
  146.     virtual OSErr GetAlias(AliasHandle& alias);
  147.         // Return the file specification as an alias handle
  148.  
  149.     virtual OSErr GetCatInfo(CInfoPBRec& cInfo);
  150.         // Return the catalog information about the this file
  151.  
  152.     virtual long GetCreationDate();
  153.         // Date the file was created
  154.  
  155.     virtual OSErr GetDataLength(long& length);
  156.         // Return the length of the data fork
  157.  
  158.     virtual OSErr GetDataMark(long& mark);
  159.         // Return the position of the mark in the data fork
  160.  
  161.     virtual long GetDirID();
  162.         // Return the directory ID stored in the FSSpec
  163.  
  164.     virtual OSErr GetFileCreator(OSType& creator);
  165.         // Return the creator of the file as found in the finder info
  166.  
  167.     virtual OSErr GetFileInfo(HParamBlockRec& pb);
  168.         // Return all the information the file manager provides
  169.  
  170.     virtual void GetFileSpec(FSSpec& theFileSpec);
  171.         // Return its file specification record
  172.  
  173.     virtual OSErr GetFileType(OSType& fileType);
  174.         // Return the type of the file as found in the finder info
  175.  
  176.     virtual OSErr GetFinderInfo(FInfo& fndrInfo);
  177.         // Return finder information about the file
  178.  
  179.     virtual OSErr GetFinderInfo(FInfo& fndrInfo, FXInfo& itsFXInfo, Boolean& isDirectory);
  180.         // Return finder information about the file
  181.         // IF isDirectory returns TRUE (indicating that it's a directory)
  182.         //         returns DInfo in fndrInfo and DXInfo in itsFXInfo
  183.         // ELSE
  184.         //         returns FInfo in fndrInfo and FXInfo in itsFXInfo
  185.  
  186.     virtual long GetModificationDate();
  187.         // Return the date the file was last modified
  188.  
  189.     virtual void GetName(CStr63& name);
  190.         // Return the name of the file
  191.  
  192.     virtual OSErr GetPathName(CStr255& pathName);
  193.         // Return the MPW style path name of the file
  194.         
  195.     virtual OSErr GetPhysicalSize(long& dataSize, long& rsrcSize);
  196.         // Returns the physical size in bytes of the data and resource fork
  197.  
  198.     virtual OSErr GetScript(ScriptCode& theScript);
  199.         // Returns the script code as stored in the extended finder info
  200.         
  201.     virtual OSErr SetModificationDate(long modificationDate);
  202.         // Sets the modification date of the file.
  203.         
  204.     virtual OSErr SetCreationDate(long creationDate);
  205.         // Sets the creation date of the file.
  206.         
  207.     virtual OSErr SetFinderInfo(const FInfo& fndrInfo);
  208.         // Sets the finder information for the file.
  209.  
  210.  
  211.     //----------------------------------------------------------------------------------------
  212.     // Volume attributes
  213.     //----------------------------------------------------------------------------------------
  214.  
  215.     virtual OSErr FlushVolume();
  216.         // Flush the volume to force any changes to take place
  217.  
  218.     virtual OSErr GetBlockSize(long& blockSize);
  219.         // Return the size of allocated blocks on the volume
  220.  
  221.     virtual OSErr GetFreeBlocks(long& freeBlocks);
  222.         // Return the number of free blocks on the volume
  223.  
  224.     virtual OSErr GetVolumeInfo(HParamBlockRec& pb);
  225.         // Return all information provided by the file manager on the volume
  226.  
  227.     virtual OSErr GetVolumeName(CStr63& name);
  228.         // Return the name of the volume
  229.  
  230.     virtual short GetVolRefNum();
  231.         // Return the volume reference number stored in the FSSpec
  232.  
  233.     virtual OSErr ExchangeFiles(TFile* aFile);
  234.         // Exchange the contents of this with the contents of another file maintaining the
  235.         // file id
  236.  
  237.     virtual Boolean IsDataForkOpen();
  238.         // True if the data fork of the file is open
  239.  
  240.     virtual Boolean IsModified();
  241.         // Checks fModDate to determine if file changed
  242.  
  243.     virtual Boolean IsRsrcForkOpen();
  244.         // True if the resource fork of the file is open
  245.  
  246.     virtual Boolean IsSameFile(TFile* aFile);
  247.         // Does this file refer to the same file as aFile?
  248.  
  249.     virtual Boolean IsStationery();
  250.         // True if this file is a stationery pad
  251.  
  252.     virtual OSErr IsVolumeLocked(Boolean& locked);
  253.         // Returns true if the volume is hardware or software locked
  254.  
  255.     virtual Boolean HasDataFork();
  256.         // Returns true if file has a data fork
  257.  
  258.     virtual Boolean HasRsrcFork();
  259.         // Returns true if file has a resource fork
  260.  
  261.     virtual Boolean HasValidFileSpec();
  262.         // Returns true if the filespec has been set to some value other than
  263.         // the initialized value.
  264.         
  265.     virtual void Modified();
  266.         // Update fModDate to the value stored by the finder
  267.  
  268.     virtual OSErr MoveAndRename(const FSSpec& dest);
  269.         // Move the file to the new destination and give it a new name
  270.  
  271.     virtual OSErr ReadData(void* buffer, long& count);
  272.         // Read count bytes from the data fork into buffer
  273.  
  274.     virtual OSErr ReadUntil(void* buffer, long& count, char untilChar);
  275.         // Read bytes from the supplied buffer until the stop character untilChar
  276.         // is found.  Returns the number of bytes actually read in count.
  277.         
  278.     virtual OSErr RenameFile(const CStr63& newName);
  279.         // Rename the file to the specified name
  280.  
  281.     virtual OSErr SetCatInfo(CInfoPBRec& cInfo);
  282.         // Set the catalog information about this file. The file reference portion of the
  283.         // record is supplied by fFileSpec.
  284.  
  285.     virtual OSErr SetDataLength(long length);
  286.         // Set the length of the data fork
  287.  
  288.     virtual OSErr SetDataMark(long mark, short fromWhere);
  289.         // Set the position of the mark in the data fork
  290.  
  291.     virtual OSErr SetFileInfo( HParamBlockRec& pb);
  292.         // Set the file information about this file. The file reference portion of the
  293.         // record is supplied by fFileSpec.
  294.  
  295.     virtual void SetName(const CStr63& newName);
  296.         // Sets the name field of the filespec but doesn't rename the file
  297.  
  298.     virtual void SetPermissions(SignedByte dataPermission,
  299.                                        SignedByte rsrcPermission);
  300.         // Set the fDataPermission and fRsrcPermission fields of the file
  301.  
  302.     virtual OSErr SetScript(ScriptCode theScript);
  303.         // Sets the script code stored in the extended finder info
  304.  
  305.     Boolean UpdateFileSpec();
  306.         // Update the file's FSSpec and notify if a change was required.
  307.  
  308.     virtual OSErr UpdateResource();
  309.         // Update the resource referenced by fRsrcRefNum
  310.  
  311.     virtual short UseResource();
  312.         // Returns the current resource file and set itself as the current file
  313.  
  314.     virtual OSErr WriteData(const void* buffer, long& count);
  315.         // Write count bytes from buffer to the data fork
  316.  
  317.     //----------------------------------------------------------------------------------------
  318.     // Scripting Support
  319.     //----------------------------------------------------------------------------------------
  320.  
  321.     virtual Boolean GetObjectProperty(CAEDesc& thePropertyValue,
  322.                                       DescType whichProperty,
  323.                                       const CAEDesc& desiredType);
  324.  
  325.     virtual void SetObjectProperty(const CAEDesc& thePropertyValue,
  326.                                    DescType whichProperty);
  327.  
  328.  
  329.     //----------------------------------------------------------------------------------------
  330.     // data members
  331.     //----------------------------------------------------------------------------------------
  332.  
  333.     FSSpec fFileSpec;                            // volume/ directory/filename
  334.  
  335.     OSType fFileType;                            // file type
  336.  
  337.     OSType fCreator;                            // creator ID
  338.  
  339.     long fModDate;                                // file mod date when last read/ saved
  340.  
  341.     short fDataRefNum;                            // Reference for reading/ writing to data
  342.                                                 // fork
  343.  
  344.     short fRsrcRefNum;                            // Reference for reading/ writing to
  345.                                                 // resource fork
  346.  
  347.     ScriptCode fScriptTag;                        // The script the file was created with
  348.  
  349.     ResourceUsage fUsesRsrcFork;                // A value of need or prefer indicates
  350.                                                 // the file uses its resource fork
  351.                                                 
  352.     SignedByte fDataPermission;                    // Permissions used when opening the data
  353.                                                 // fork
  354.  
  355.     SignedByte fRsrcPermission;                    // Permissions used when opening the
  356.                                                 // resource fork
  357.  
  358.     Boolean fStationery;                        // True if this is stationery
  359.  
  360.     Boolean fUsesDataFork;                        // True if the file uses its data fork
  361.  
  362.     Boolean fKeepDataOpen;                        // Will the data fork be left open?
  363.  
  364.     Boolean fKeepRsrcOpen;                        // Will the rsrc fork be left open?
  365.  
  366. protected:
  367.     AliasHandle        fAlias;
  368. };
  369.  
  370.  
  371. //----------------------------------------------------------------------------------------
  372. // Global function declarations
  373. //----------------------------------------------------------------------------------------
  374.  
  375. extern TFile* NewFile(OSType itsFileType,
  376.                          OSType itsCreator,
  377.                          Boolean usesDataFork,
  378.                          ResourceUsage usesRsrcFork,
  379.                          Boolean keepsDataOpen,
  380.                          Boolean keepsRsrcOpen);
  381.     // A convenience function. Create a TFile, initialize it, and return a reference to
  382.     // it. Signals Failure if it cannot allocate the object.
  383.  
  384.  
  385. #endif
  386.  
  387.  
  388.